<template>
  <el-container class="main_con">
    <div class="filter_con ds_block">
      <div class="button_area"><el-button v-has size="medium" type="primary" @click="addgift">新增活动</el-button></div>
      <!-- <div class="filter_area"><el-button size="medium" @click="search">搜索</el-button></div> -->
    </div>
    <div class="list_con">
      <el-table class="main-loading" @selection-change="SelectHadnle" :data="list" element-loading-text="" fit highlight-current-row>
        <el-table-column type="selection" width="55" align="center"></el-table-column>
        <el-table-column prop="name" label="活动名"></el-table-column>
        <el-table-column prop="start_time" label="开始时间"></el-table-column>
        <el-table-column prop="end_time" label="结束时间"></el-table-column>
        <el-table-column label="操作">
          <template slot-scope="scope">
            <el-button v-has type="text" @click="EditHandle(scope.row.id)">编辑</el-button>
            <el-button v-has type="text" @click="handleClose(scope.row.id)">删除</el-button>
          </template>
        </el-table-column>
      </el-table>
      <div class="table_footer">
        <!-- <el-button size="medium">批量删除</el-button> -->
        <el-pagination @current-change="ChangeCurrent" class="pages" background layout="prev, pager, next" :total="total"></el-pagination>
      </div>
    </div>
    <!-- <el-drawer class="w_80" title="编辑活动" :visible.sync="drawer" :direction="direction">
      <edituser @on-close="beClose" :uid='user_id' :user_type="user_type"></edituser>
    </el-drawer> -->
  </el-container>
</template>

<script>
import {mapGetters} from 'vuex';
import {getgiftlist,delgift} from '@/api/mall/activity';
import {fitter_keyword} from '@/utils/index';
export default {
  data() {
    return {
      params: {
        name: '',
        mobile: '',
        begin_date: '',
        end_date: ''
      },
      paramsdf: {},
      page: 1,
      size: 10,
      total: 0,
      listLoading: true,
      list: [],
      drawer: false,
      direction: 'rtl',
      user_id: '',
      user_type: 'add',
      selectionData: []
    };
  },

  computed: {
    ...mapGetters(['allroleslist'])
  },
  mounted() {
    this.getlist();
  },

  methods: {
    search() {
      this.paramsdf = fitter_keyword(this.params);
      this.getlist();
    },
    //启用，禁用
    EnableHandle(data) {
      let _this = this;
      let status = Number(data.status != '正常');
      this.$confirm(status ? '确认启用？' : '确认禁用？')
        .then(_ => {
          let params = data;
          params.status = status;
          editadminuser(params).then(res => {
            _this.getlist();
          });
        })
        .catch(_ => {});
    },
    //选择
    SelectHadnle(selection) {
      this.selectionData = selection;
    },
    //删除
    handleClose(id) {
      let _this = this;
      this.$confirm('确认删除？')
        .then(_ => {
          let data = {
            id: id
          };
          delgift(data).then(res => {
            _this.getlist();
          });
        })
        .catch(_ => {});
    },
    //新增
    addgift() {
      this.$router.push({
        path: '/activity/editgift'
      });
    },
    //编辑
    EditHandle(id) {
      this.$router.push({
        path: '/activity/editgift',
        query: {
          id: id
        }
      });
    },
    //编辑完成
    beClose() {
      (this.drawer = false), this.getlist();
    },
    //获取列表
    getlist() {
      this.listLoading = true;
      var data = this.params;
      data.page=this.page;
      data.size=this.size
      getgiftlist(data).then(res => {
        var jsondata = res.msg;
        this.list = jsondata.data;
        this.total = jsondata.total;
        // this.list = response.data.items
        this.listLoading = false;
      });
    },
    //获取时间
    gettime(value) {
      this.params.begin_date = value[0];
      this.params.end_date = value[1];
    },
    //切换页码
    ChangeCurrent(page) {
      this.page = page;
      this.getlist();
    }
  }
};
</script>

<style lang="scss" scoped></style>
